/*
* cnpm i webpack webpack-cli -g
* cnpm i webpack --save
* 写配置文件 webpack.config.js
* 安装及配置对应的loader
* 特殊loader： 安装sass-loader的同时 需要安装 node-sass
* */
const htmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
module.exports = {
    entry: './index.js',
    output: {
        filename: "package.js",
        path: path.resolve(__dirname, './dist')
    },
    module : {
        rules: [
            {
                test: /\.css$/,
                use: ['style-loader', 'css-loader']
            },
            {
                test: /\.scss$/,
                use: ['style-loader', 'css-loader', 'sass-loader']
            },
            {
                test: /\.jpg$/,
                use: ['url-loader']
            }
        ]
    },
    mode: 'development',
    plugins: [
        new htmlWebpackPlugin({
            template: './index.html',
            inject: 'head',
            minify: {
                collapseWhitespace: true, // 清除空格
                removeComments: true, // 清除注释
            }
        })
    ],
    devServer: {
        contentBase: path.join(__dirname, 'dist'),
        // compress: true,  是否压缩
        port: 8080, // 端口号
        open: true, // 自动打开浏览器
        hot: true // 自动刷新浏览器
        // http://localhsot:8080
    }
};


